package com.example.myapplication.fragment;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;

import com.example.myapplication.R;

public class f4 extends Fragment {

    private TextView lufei;
    private RadioGroup radioGroup;
    private RadioButton rbShitou;
    private RadioButton rbQiandao;
    private RadioButton rbBu;
    private Button button;
    View view;
    Context context;
    caa caa;
    public f4() {
        // Required empty public constructor
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        view=inflater.inflate(R.layout.fragment_f4, container, false);
        context=getContext();
        initView();
        getString();
        return view;
    }
    /*
    跳转传值
     */
    public void getString(){

       button.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View v) {
               RadioButton radioButton = (RadioButton) view.findViewById(radioGroup.getCheckedRadioButtonId());
               String game=radioButton.getText().toString();
               caa.change(game);

           }
       });
    }
/*
初始化控件
 */
    private void initView() {
        lufei = (TextView) view.findViewById(R.id.lufei);
        radioGroup = (RadioGroup) view.findViewById(R.id.radioGroup);
        rbShitou = (RadioButton) view.findViewById(R.id.rb_shitou);
        rbQiandao = (RadioButton) view.findViewById(R.id.rb_qiandao);
        rbBu = (RadioButton) view.findViewById(R.id.rb_bu);
        button = (Button) view.findViewById(R.id.button);
    }
    public interface caa {
        public void change(String game);
    }

    @Override
    public void onAttach(@NonNull Context context) {
        super.onAttach(context);
        caa = (caa) context;
    }
}
